﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class ReturnMtlProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<ReturnMtlEntity> entryList = new List<ReturnMtlEntity>();

            ReturnMtlEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new ReturnMtlEntity();
                    entry.ReceiveNo = item[ReturnMtlEntity.RECEIVE_NO].ToString();
                    entry.ReceiveType = item[ReturnMtlEntity.RECEIVE_TYPE].ToString();
                    entry.ApproveStatus = item[StorageEntity.APPROVE_STATUS].ToString();
                    entry.JobNum = item[ReturnMtlEntity.JOB_NUM].ToString();

                    entry.MtlPartNum = item[ReturnMtlEntity.MTL_PARTNUM].ToString();
                    entry.OldPartNum = item[ReturnMtlEntity.OLD_PARTNUM].ToString();
                    entry.PartDescription = item[ReturnMtlEntity.PART_DESCRIPTION].ToString();
                    entry.RequiredQty = Convert.ToDecimal(item[ReturnMtlEntity.REQUIRED_QTY].ToString());
                    entry.ApplyQty = Convert.ToDecimal(item[ReturnMtlEntity.APPLY_QTY].ToString());
                    entry.TranQty = Convert.ToDecimal(item[ReturnMtlEntity.TRAN_QTY].ToString());
                    entry.NetWeight = Convert.ToDecimal(item[ReturnMtlEntity.NET_WEIGHT].ToString());
                    entry.DueDate = string.IsNullOrEmpty(item[ReturnMtlEntity.DUE_DATE].ToString()) ? SqlDateTime.Null : Convert.ToDateTime(item[ReturnMtlEntity.DUE_DATE].ToString());
                    entry.IUM = item[ReturnMtlEntity.IUM_S].ToString();
                    entry.WareHouseCode = item[ReturnMtlEntity.WARE_HOUSE_CODE].ToString();
                    entry.WareHouseDesc = item[ReturnMtlEntity.WARE_HOUSE_DESC].ToString();

                    entry.SaPartNum = item[ReturnMtlEntity.SA_PARTNUM].ToString();
                    entry.OnHandQty = Convert.ToDecimal(item[ReturnMtlEntity.ON_HANDQTY].ToString());

                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
